package com.developer.platform.application.query.assembler;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.developer.platform.application.query.dto.LogDto;
import com.developer.platform.application.query.dto.ResponseModel;
import com.developer.platform.domain.Log;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.stereotype.Component;

/**
 * @author ：qiaoliang
 * @date ：2021-01-07
 */
@Component
public class LogAssembler extends BaseAssembler{

  public LogDto toLogDto(Log log){
    LogDto logDto = new LogDto();
    BeanUtil.copyProperties(log, logDto);
    return logDto;
  }

  public List<LogDto> toLogDto(List<Log> list){
    List<LogDto> collect = list.stream().map(this::toLogDto)
        .collect(Collectors.toList());
    this.userName(collect);
    return collect;
  }

  public ResponseModel<LogDto> toLogDto(IPage<Log> page){
    List<LogDto> collect = this.toLogDto(page.getRecords());
    this.userName(collect);
    return new ResponseModel<>(collect, (int)page.getTotal());
  }

}
